import each from "./each"
import { cb } from "../util/iteratee";
//内部函数，用于汇总“分组依据”操作。
export function group(behavior, partition?) {
  return function (obj, iteratee, context) {
    var result = partition ? [[], []] : {}
    iteratee = cb(iteratee, context);
    each(obj, function (value, index) {
      var key = iteratee(value, index, obj)
      behavior(result, value, key)
    })
    return result;
  }
}
export const has = function (obj, path): boolean {
  return obj != null && Object.hasOwnProperty.call(obj, path);
}

export default group(function (result, value, key) {
  if (has(result, key)) result[key].push(value); else result[key] = [value];
});